package com.myqf.d7_日期类_druid连接池.dao设计模式2;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 作者：黎杭
 * 日期：2020/2/18
 */
public class ConnectionUtil {

    public static final String USER_NAME = "root";// crlt+shift+u转换大小写
    public static final String PASSWORD = "qq123123";// crlt+shift+u转换大小写
    public static final String URL = "jdbc:mysql://localhost:3306/test_db2?serverTimezone=GMT";// crlt+shift+u转换大小写

    /**
     * 获取连接对象
     *
     * @return
     */
    public static Connection getConnection() {
        try {
            Connection connection = DriverManager.getConnection(URL, USER_NAME, PASSWORD);// 获取Connection对象
            return connection;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 关闭连接的操作
     *
     * @param connection
     */
    public static void close(Connection connection) {

        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
